<?php namespace app\admin\controller;

class Admin extends Common{
    //动作
    public function index(){
    //此处书写代码...
        return view();
    }
    //退出
    public  function  quit(){
       $uid= Session::get('uid');
        Db::table('user')->where("uid",$uid)->update(['session'=>0]);
        Session::flush();
        message('退出成功','admin.entry.index','success');
    }
    /**
     * 修改密码
     */
    public  function  changepass(){
        $uid= Session::get('uid');
        if(IS_POST){
//            p($_POST);die;
            $password=Crypt::encrypt($_POST['password']);
            $old_password=Db::table('user')->where('uid',$uid)->get(['password']);
            $old_password=$old_password[0]['password'];
//            p()
//            p($old_password);die;
            if($_POST['new_password']!=$_POST['confirm_password']){
                message('两次输入的密码不一致','changepass','error');
            }
            if($password!=$old_password){
                 message('原密码不正确','changepass','error');
            }
            $newpassword=Crypt::encrypt($_POST['new_password']);
          $res=Db::table('user')->where('uid',$uid)->update(['password'=>$newpassword]);
            if($res){
                message('操作成功','admin.entry.index','success');
            }else{
                message('操作失败','changepass','error');
            }
        }
        return view();
    }
}
